home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Devil's Cubes 1.0.1 / source / Devil’s Cubes ƒ / Cube code / cube files.c next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  4.1 KB  |  159 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        cube files.c
  4.  
  5. Purpose:    This module handles the standard file dialogs for getting
  6.             saved games and saving current games.
  7.  
  8.  
  9. Devil’s Cubes -- a simple cubes puzzle
  10. Copyright (C) 1993 Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "Script.h"
  30. #include "cube files.h"
  31. #include "cube load-save.h"
  32. #include "msg graphics.h"
  33. #include "msg environment.h"
  34.  
  35. Boolean GetSourceFile(FSSpec *gameFile, Boolean useOldGame)
  36. {
  37.     Point                where;
  38.     OSErr                isHuman;
  39.     StandardFileReply    reply;
  40.     SFReply                oldReply;
  41.     unsigned int        count;
  42.     SFTypeList            typeList;
  43.     FInfo                fndrInfo;
  44.     long                procID;
  45.     int                    i;
  46.     
  47.     typeList[0]='DcSG';
  48.     isHuman=FALSE;
  49.     if ((gStandardFile58) && (!useOldGame))
  50.     {
  51.         StandardGetFile(0L, 1, typeList, &reply);
  52.     }
  53.     else
  54.     {
  55.         where.h = (gMainScreenBounds.right - 348)/2;
  56.         where.v = (gMainScreenBounds.bottom - 200)/3;
  57.         SFGetFile(where, "\p", 0L, 1, typeList, 0L, &oldReply);
  58.         
  59.         reply.sfGood = oldReply.good;
  60.         if (reply.sfGood)
  61.         {
  62.             reply.sfType = oldReply.fType;
  63.             isHuman=GetWDInfo(oldReply.vRefNum, &reply.sfFile.vRefNum,
  64.                                 &reply.sfFile.parID, &procID);
  65.             if (isHuman!=noErr)
  66.             {
  67.                 reply.sfFile.vRefNum = oldReply.vRefNum;
  68.                 reply.sfFile.parID = 0;
  69.             }
  70.             count=oldReply.fName[0];
  71.             for (i=0; i<=count; i++)
  72.                 reply.sfFile.name[i]=oldReply.fName[i];
  73.             
  74.             reply.sfScript=smSystemScript;
  75.             isHuman=HGetFInfo(reply.sfFile.vRefNum, reply.sfFile.parID,
  76.                                 reply.sfFile.name, &fndrInfo);
  77.             reply.sfFlags=(isHuman==noErr) ? fndrInfo.fdFlags : 0;
  78.             
  79.             reply.sfIsFolder=FALSE;
  80.             reply.sfIsVolume=FALSE;
  81.         }
  82.     }
  83.  
  84.     if ((reply.sfGood) && (!isHuman))
  85.         MyMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name,
  86.                             gameFile);
  87.         
  88.     return ((reply.sfGood) && (!isHuman));
  89. }
  90.  
  91. Boolean GetDestFile(FSSpec *gameFile, Boolean *deleteTheThing)
  92. {
  93.     unsigned int        count;
  94.     Str255                otherName;
  95.     StandardFileReply    reply;
  96.     SFReply                oldReply;
  97.     Point                where;
  98.     FInfo                fndrInfo;
  99.     long                procID;
  100.     OSErr                isHuman;
  101.     int                    i;
  102.         
  103.     if (gStandardFile58)
  104.         StandardPutFile("\pSave Devil’s Cubes game as...", "\p", &reply);
  105.     else
  106.     {
  107.         where.h = (gMainScreenBounds.right - 304)/2;
  108.         where.v = (gMainScreenBounds.bottom - 184)/3;
  109.         SFPutFile(where, "\pSave Devil’s Cubes game as...", "\p", 0, &oldReply);
  110.         reply.sfGood = oldReply.good;
  111.         if (reply.sfGood)
  112.         {
  113.             isHuman=GetWDInfo(oldReply.vRefNum, &reply.sfFile.vRefNum,
  114.                                 &reply.sfFile.parID, &procID);
  115.             if (isHuman!=noErr)
  116.             {
  117.                 reply.sfFile.vRefNum = oldReply.vRefNum;
  118.                 reply.sfFile.parID = 0;
  119.             }            
  120.             count=oldReply.fName[0];
  121.             for (i=0; i<=count; i++)
  122.                 reply.sfFile.name[i]=oldReply.fName[i];
  123.             
  124.             reply.sfScript = smSystemScript;
  125.             isHuman=HGetFInfo(reply.sfFile.vRefNum, reply.sfFile.parID,
  126.                                 reply.sfFile.name, &fndrInfo);
  127.             reply.sfReplacing=(isHuman!=fnfErr);
  128.             
  129.             reply.sfIsFolder=FALSE;
  130.             reply.sfIsVolume=FALSE;
  131.         }
  132.     }
  133.  
  134.     if (reply.sfGood)
  135.     {
  136.         *deleteTheThing=reply.sfReplacing;    
  137.         MyMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name,
  138.                         gameFile);
  139.     }
  140.     
  141.     return (reply.sfGood);
  142. }
  143.  
  144. pascal OSErr MyMakeFSSpec(short vRefNum, long parID, ConstStr255Param fileName,
  145.     FSSpecPtr myFSS)
  146. {
  147.     int            i;
  148.     
  149.     if (gHasFSSpecs)
  150.         FSMakeFSSpec(vRefNum, parID, fileName, myFSS);
  151.     else
  152.     {
  153.         myFSS->vRefNum=vRefNum;
  154.         myFSS->parID=parID;
  155.         for (i=fileName[0]; i>=0; i--)
  156.             myFSS->name[i]=fileName[i];
  157.     }
  158. }
  159.